package com.yeren.servlet.tarena.web;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class DeleteEmpServlet extends HttpServlet {
	/*
	 * 使用请求中的name,contact两组参数值 分别使用getParameter和getParameterValues方法获取
	 */
	public void service(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		//
		resp.setContentType("text/html;charset=utf-8");
		PrintWriter out = resp.getWriter();
		int id=Integer.parseInt(req.getParameter("id"));
		//
		Connection conn = null;
		PreparedStatement stmt = null;
		ResultSet rs=null;
		try {
			Class.forName("oracle.jdbc.OracleDriver");
			conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl","scott", "tiger");
			stmt = conn.prepareStatement("delete from liu_temp where id=?");
			stmt.setInt(1,id);
			stmt.executeUpdate();
			resp.sendRedirect("list");//重定向
		} catch (Exception e) {
			e.printStackTrace();
			out.print("系统繁忙，稍后重试");
		} finally {         
			if (conn != null) {
				try {
					conn.close();
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		}

	}
}
